<template>  
    <section>
      <div class="box">
        <div class="square" style="--i:0;"></div>
        <div class="square" style="--i:1;"></div>
        <div class="square" style="--i:2;"></div>
        <div class="square" style="--i:3;"></div>
        <div class="square" style="--i:4;"></div>
        <div class="square" style="--i:5;"></div>
  
        <div class="container">
          <div class="form">
            <h2>REGISTER to CodePen</h2>
            <form @submit.prevent="register">
              <div class="inputBx">
                <input type="text" v-model="form.username" required />
                <span>Username</span>
                <font-awesome-icon icon="user" />
              </div>
  
             <!--  <div class="inputBx">
                <input type="email" v-model="form.email" required />
                <span>Email</span>
                <font-awesome-icon icon="envelope" />
              </div> -->
  
              <div class="inputBx password">
                <input id="password-input" type="password" v-model="form.password" required />
                <span>Password</span>
                <a href="#" class="password-control" @click.prevent="show_hide_password('password-input', $event)"></a>
                <font-awesome-icon icon="lock" />
              </div>
  
              <div class="inputBx password">
                <input id="confirmpassword-input" type="password" v-model="form.confirmPassword" required />
                <span>Confirm Password</span>
                <a href="#" class="password-control" @click.prevent="show_hide_password('confirmpassword-input', $event)"></a>
                <font-awesome-icon icon="lock" />
              </div>
  
              <label class="remember"><input type="checkbox" /> I agree to terms</label>
              <div class="inputBx">
                <input type="submit" value="Register" />
              </div>
            </form>
  
            <p>Already have an account? <a href="#">Login</a></p>
          </div>
        </div>
      </div>
    </section>
  </template>
  
  <script setup>
  import { reactive } from 'vue'
  import { ElMessage } from 'element-plus'
  import { userregister } from '@/api/user'  // 你需要实现此方法
  import { useRouter } from 'vue-router'
  
  const router = useRouter()
  
  const form = reactive({
    username: '',
    password: '',
    usertype:'客户',
    confirmPassword: ''
  })
  
  const register = async () => {
    if (form.password !== form.confirmPassword) {
      ElMessage.error('Passwords do not match')
      return
    }
    const result = await userregister(form)
    if (result.code === 0) {
      ElMessage.success(result.msg || '注册成功')
      router.push('/') // 注册成功跳转登录
    } else {
      ElMessage.error(result.msg || '注册失败')
    }
  }
  
  function show_hide_password(elementid,event) {
    console.log("ssssssss")
    const target = event.currentTarget
    const input = document.getElementById(elementid)
    if (input.getAttribute('type') === 'password') {
      target.classList.add('view')
      input.setAttribute('type', 'text')
    } else {
      target.classList.remove('view')
      input.setAttribute('type', 'password')
    }
  }
  </script>
  
 
  
  <style scoped>
  @import url('https://fonts.googleapis.com/css2?family=El+Messiri:wght@700&display=swap');
  
  * {
    margin: 0;
    padding: 0;
    font-family: 'El Messiri', sans-serif;
  }
  
  body {
    background: #031323;
    overflow: hidden;
  }
  
  .fas {
    width: 32px;
  }
  .fa-solid {
  display: inline-block;
  font-style: normal;
  font-variant: normal;
  text-rendering: auto;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  vertical-align: middle;  /* 这里重点 */
  line-height: 1;
}


  section {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  background: linear-gradient(-45deg, #ee7752, #e73c7e, #23a6d5, #23d5ab); /* 你的渐变背景 */
  display: flex;
  justify-content: center;
  align-items: center;
  overflow: hidden;
}

  
  @keyframes gradient {
    0% {
      background-position: 0% 50%;
    }
  
    50% {
      background-position: 100% 50%;
    }
  
    100% {
      background-position: 0% 50%;
    }
  }
  
  .box {
    position: relative;
    width: 100%;
    max-width: 440px;
    min-height: 480px;
    margin-bottom: 60px;
  }
  
  .box .square {
    position: absolute;
    background: rgba(255, 255, 255, 0.1);
    backdrop-filter: blur(5px);
    box-shadow: 0 25px 45px rgba(0, 0, 0, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.15);
    border-radius: 15px;
    animation: square 10s linear infinite;
    animation-delay: calc(-1s * var(--i));
  }
  
  @keyframes square {
    0%,
    100% {
      transform: translateY(-20px);
    }
  
    50% {
      transform: translateY(20px);
    }
  }
  
  /* 调整方块位置大小，避免溢出屏幕 */
  .box .square:nth-child(1) {
    width: 80px;
    height: 80px;
    top: 10px;
    right: 10px;
  }
  
  .box .square:nth-child(2) {
    width: 60px;
    height: 60px;
    top: 140px;
    left: 0px;
    z-index: 2;
  }
  
  .box .square:nth-child(3) {
    width: 50px;
    height: 50px;
    bottom: 70px;
    right: 10px;
    z-index: 2;
  }
  
  .box .square:nth-child(4) {
    width: 40px;
    height: 40px;
    bottom: 40px;
    left: 10px;
  }
  
  .box .square:nth-child(5) {
    width: 40px;
    height: 40px;
    top: 10px;
    left: 60px;
  }
  
  .box .square:nth-child(6) {
    width: 70px;
    height: 70px;
    top: 190px;
    right: 0px;
    z-index: 2;
  }
  
  .container {
    position: relative;
    padding: 40px 50px;
    width: 100%;
    max-width: 400px; /* 更宽适应屏幕 */
    min-height: 380px;
    display: flex;
    justify-content: center;
    align-items: center;
    background: rgba(255, 255, 255, 0.1);
    backdrop-filter: blur(5px);
    border-radius: 10px;
    box-shadow: 0 25px 45px rgba(0, 0, 0, 0.2);
    margin: 0 auto;
  }
  
  .container::after {
    content: '';
    position: absolute;
    top: 5px;
    right: 5px;
    bottom: 5px;
    left: 5px;
    border-radius: 5px;
    pointer-events: none;
    background: linear-gradient(
      to bottom,
      rgba(255, 255, 255, 0.1) 0%,
      rgba(255, 255, 255, 0.1) 2%
    );
  }
  
  .form {
    position: relative;
    width: 100%;
    height: 100%;
  }
  
  .form h2 {
    color: #fff;
    letter-spacing: 2px;
    margin-bottom: 30px;
    text-align: center;
  }
  
  .inputBx {
    position: relative;
    width: 100%;
    margin-bottom: 20px;
  }
  
  .inputBx input {
    width: 100%; /* 宽度100%更适合不同屏幕 */
    outline: none;
    border: 1px solid rgba(255, 255, 255, 0.2);
    background: rgba(255, 255, 255, 0.2);
    padding: 8px 10px 8px 40px;
    border-radius: 15px;
    color: #fff;
    font-size: 16px;
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.05);
    box-sizing: border-box;
  }
 

  .password-control {
    position: absolute;
    top: 11px;
    right: 10px;
    display: inline-block;
    width: 20px;
    height: 20px;
    background: url(https://snipp.ru/demo/495/no-view.svg) 0 0 no-repeat;
    transition: 0.5s;
    cursor: pointer;
  }
  
  .password-control.view {
    background: url(https://snipp.ru/demo/495/view.svg) 0 0 no-repeat;
    transition: 0.5s;
  }
  
  .inputBx svg {
  position: absolute;
  top: 13px;
  left: 13px;
  width: 16px;   /* 调整图标大小 */
  height: 16px;
  color: #fff;   /* 颜色 */
  pointer-events: none; /* 避免鼠标事件影响 */
}

  
  .inputBx input[type='submit'] {
    background: #fff;
    color: #111;
    max-width: 100px;
    padding: 8px 10px;
    box-shadow: none;
    letter-spacing: 1px;
    cursor: pointer;
    transition: 1.5s;
    border-radius: 15px;
  }
  
  .inputBx input[type='submit']:hover {
    background: linear-gradient(
      115deg,
      rgba(0, 0, 0, 0.1),
      rgba(255, 255, 255, 0.25)
    );
    color: #fff;
    transition: 0.5s;
  }
  
  .inputBx input::placeholder {
    color: #fff;
  }
  
  .inputBx span {
    position: absolute;
    left: 30px;
    padding: 10px;
    display: inline-block;
    color: #fff;
    transition: 0.5s;
    pointer-events: none;
  }
  
  .inputBx input:focus ~ span,
  .inputBx input:valid ~ span {
    transform: translateX(-30px) translateY(-25px);
    font-size: 12px;
  }
  
  .form p {
    color: #fff;
    font-size: 15px;
    margin-top: 5px;
    text-align: center;
  }
  
  .form p a {
    color: #fff;
  }
  
  .form p a:hover {
    background-color: #000;
    background-image: linear-gradient(to right, #434343 0%, black 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
  }
  
  .remember {
    position: relative;
    display: inline-block;
    color: #fff;
    margin-bottom: 10px;
    cursor: pointer;
    user-select: none;
    font-size: 14px;
  }
  </style>
  